<template>
  <BasicModal v-bind="$attrs" @register="register">
    <CodeEditor v-model:value="value" :mode="modeValue" />
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import { CodeEditor, MODE } from '/@/components/CodeEditor';
  import { BasicModal, useModalInner } from '/@/components/Modal';

  export default defineComponent({
    components: {
      BasicModal,
      CodeEditor,
    },
    props: {
      method: { type: String, defaultValue: 'add' },
      formData: { type: Object },
    },
    setup() {
      const modelRef = ref({});
      const modeValue = ref<MODE>(MODE.JSON);
      const value = ref({});
      const [register, { setModalProps }] = useModalInner((data) => {
        data && onDataReceive(data);
        setModalProps({
          title: data ? '新增' : '编辑',
        });
      });

      function onDataReceive(data) {
        value.value = `
        {
          "name": "hahsdh"
        }
        `;
      }
      return { register, value, modeValue, model: modelRef };
    },
  });
</script>
